import Vue from 'vue'
import Router from 'vue-router'
import {routers} from "./routers"
import VueRouter from 'vue-router'
import Cookies from 'js-cookie';

Vue.use(Router);

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

// export default new Router({
//   mode: 'hash',
//   base: process.env.BASE_URL,
//   routes:routes,
// })


// 路由配置
const RouterConfig = {
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: routers
};

export const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
  let userName=Cookies.get("userName");
  // console.log("凭证：：",userName);
  // if(to.name=='login'||to.name=='register'){
  //   next();
  // }else if(userName!="" && userName!==null && userName!=undefined){
  //   next();
  // }else{
  //   next({
  //     name: 'login'
  //   });
  // }

  next();

  // console.log("====>",to)
});
